<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Model;

use App\Utils\Qiniu;
use Hyperf\DbConnection\Model\Model;

/**
 * @property int $user_id
 * @property string $account
 * @property string $nickname
 * @property int $gender
 * @property string $avatar_img
 * @property \Carbon\Carbon $create_time
 * @property \Carbon\Carbon $update_time
 * @property int $delete_time
 */
class User extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user';

    protected $primaryKey = 'user_id';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['user_id' => 'integer', 'gender' => 'integer', 'create_time' => 'datetime', 'update_time' => 'datetime', 'delete_time' => 'integer'];

    /**
     * 头像图片获取器.
     * @param $value
     * @return string
     */
    public function getAvatarImgAttribute($value)
    {
        return Qiniu::getDownLoadurl($value);
    }

    /**
     * 性别属性获取器.
     * @param $value
     * @param $data
     * @return string
     */
    public function getGenderNameAttribute()
    {
        return get_gender_name($this->gender);
    }
}
